import request from "@/utils/request";

enum API {
    HASSPU_URL = '/admin/product/',
    ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
    IMAGE_URL = '/admin/product/spuImageList/',
    SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
    ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
    ADDSPU_URL = '/admin/product/saveSpuInfo',
    UPDATESPU_URL = '/admin/product/updateSpuInfo',
    ADDSKU_URL = '/admin/product/saveSkuInfo',
    SKUINFO_URL = '/admin/product/findBySpuId/',
    REMOVESPU_URL = '/admin/product/deleteSpu/'
}

// 获取某一个三级分类下已有的spu数据
export const reqHasSpu = (page: any, limit: any, category3Id: any) => request.get<any, any>(API.HASSPU_URL + `${page}/${limit}?category3Id=${category3Id}`)

// 获取全部的spu品牌的数据
export const reqAllTradeMark = () => request.get<any, any>(API.ALLTRADEMARK_URL)

// 获取某一个已有spu下全部商品的图片地址
export const reqSpuImageList = (spuId: any) => request.get<any, any>(API.IMAGE_URL + spuId)

// 获取某一个已有的spu拥有多少个销售属性
export const reqSpuHasSaleAttr = (spuId: any) => request.get<any, any>(API.SPUHASSALEATTR_URL + spuId)

// 获取整个项目全部的销售属性
export const reqAllSaleAttr = () => request.get<any, any>(API.ALLSALEATTR_URL)

// 添加新的spu接口
// 更新已有的spu接口
export const reqAddOrUpdateSpu = (data: any) => {
    if (data.id) {
        return request.post<any, any>(API.UPDATESPU_URL, data)
    } else {
        return request.post<any, any>(API.ADDSPU_URL, data)
    }
}

// 添加sku的方法
export const reqAddSku = (data: any) => request.post<any, any>(API.ADDSKU_URL, data)

// 获取sku数据
export const reqSkuList = (spuId: any) => request.get<any, any>(API.SKUINFO_URL + spuId)

// 删除已有的spu
export const rqRemoveSpu = (spuId: any) => request.delete<any, any>(API.REMOVESPU_URL + spuId)





















